package com.stellar.auth.controller.admin.authPermission;

import com.stellar.auth.controller.admin.authPermission.vo.AuthPermissionRequestPageVO;
import com.stellar.auth.controller.admin.authPermission.vo.AuthPermissionRequestVO;
import com.stellar.auth.controller.admin.authPermission.vo.AuthPermissionResponseVO;
import com.stellar.auth.controller.admin.authPermission.vo.AuthPermissionTreeVO;
import com.stellar.auth.domain.authPermission.AuthPermissionDomainService;

import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.bean.Result;
import com.stellar.web.core.constants.AuthUserConstants;
import com.stellar.web.core.validator.ValidatorRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限表控制器
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-16 18:07:20
 */
@RequestMapping("/api-admin/authPermission")
@RestController("adminAuthPermissionController")
@Slf4j
public class AuthPermissionController {

    @Resource
    private AuthPermissionDomainService authPermissionDomainService;

    /**
     * 分页查询权限表
     */
    @ValidatorRole
    @PostMapping("/page")
    public Result<PageResult<AuthPermissionResponseVO>> page(@RequestBody AuthPermissionRequestPageVO requestPageVO) {
        return Result.success(authPermissionDomainService.page(requestPageVO));
    }

    /**
     * 新增权限表
     */
    @ValidatorRole
    @PostMapping("/create")
    public Result<Boolean> create(@RequestBody AuthPermissionRequestVO requestVO) {
        return Result.success(authPermissionDomainService.insert(requestVO));
    }

    /**
     * 修改权限表
     */
    @ValidatorRole
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody AuthPermissionRequestVO requestVO) {
        return Result.success(authPermissionDomainService.update(requestVO));
    }

    /**
     * 删除权限表
     */
    @ValidatorRole
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.success(authPermissionDomainService.delete(id));
    }

    /**
     * 获取权限表详情
     */
    @ValidatorRole
    @GetMapping("/get/{id}")
    public Result<AuthPermissionResponseVO> get(@PathVariable("id") Long id) {
        return Result.success(authPermissionDomainService.get(id));
    }

    /**
     * 获取权限树列表
     */
    @ValidatorRole
    @GetMapping("/getPermissionTree")
    public Result<List<AuthPermissionTreeVO>> getPermissionTree() {
        return Result.success(authPermissionDomainService.getPermissionTree());
    }

    /**
     * 获取当前用户权限列表
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN,  AuthUserConstants.SCHOOL_ADMIN})
    @GetMapping("/getPermissionListByCurrentUser")
    public Result<List<AuthPermissionResponseVO>> getPermissionListByCurrentUser() {
        return Result.success(authPermissionDomainService.getPermissionListByCurrentUser());
    }
}
